define([
    'Util',
    'list',
    'dialog',
    'select',
    'text!tpl/requirement/viewSubTask.tpl',
    'text!tpl/requirement/taskTab.tpl',
    'text!tpl/requirement/taskAss.tpl',
    'tab',
    'select',
    'cookie',
    '../common/getPath',
    'form',
    'upload',
    '../requirement/fileList',
    '../common/getQueryString',
    '../common/dateFormat'
], function(Util, List, Dialog, Select, vSubtasks, tabletpl, taskAss, Tab, Select, $cookie, AjaxPath, Form, Upload, fileList, getQueryString) {
    require(['style!css/style.css']);
    var $el=null,
        $tabel = null;
    var _indexModule = null,
        list = null,
        tab = null,
        tplId = null,
        useMode = null,
       // projectJsonData = null,        //记录当前页面选择的是51，9，还是4
        viewSubTaskData = null,
        viewSubTaskTable = null,
        tableData = null,
        Authority = null,
        allocateValue = null,
        viewSubTaskAssSelectId = null,
        viewSubTaskAssSelect = null,
        tryPeopleData =null,
        viewSubTaskStatus = null,
        tryPeople = null,
        dialog = null,
        activeData = null;
    var initialize = function(indexModule, options, tabItem){
        $el = $(vSubtasks);
        $tabel = $(tabletpl);
        _indexModule = indexModule;
        $(tabItem).on("tabActive", function() {
            tabItem.show(true); // 刷新表单
        });
        tab = tabItem;
        this.content=$el;
        tplId = options.menuId;
        viewSubTaskData = getQueryString("id") ? {id: getQueryString("id")} : options;
        // 业务相关代码
        //viewSubTaskData = {"id":11,"ids":null,"requireTitle":"任务修改测试","requireType":"require","tryPeople":"1","sprintId":null,"healthStatus":null,"priStatus":"3","importStatus":null,"status":0,"parentId":4,"requireNum":null,"completionTime":null,"sprint":null,"sprintName":null,"parentRequirePojo":null,"likeEndTime":null,"likeMoreTime":null,"reallyUseTime":null,"issueId":null,"serialNumber":null,"updateTime":1505898326000,"splitStatus":null,"moduleIdList":null,"linkNumbers":null,"creater":null,"createTime":1505869447000,"describe":null,"starTime":null,"changeStatus":null,"presentDepartment":null,"presentPeople":null,"extend":null,"proposeTime":null,"activityIdList":null,"tagIdList":null,"projectId":null,"systemId":334,"systemName":null,"isdel":null,"type":3,"userName":null,"updater":null,"attachmentIdList":null,"statusName":"未开始","priStatusName":"高","tryPeopleName":"王健飞"};
        
       
        getEditTaskData();

    };
    //按钮点击
    var eventInit = function (){
        //页面除dialog按钮功能
        $el.on('click', '#viewSubTaskAddBtn', addTask);//新建子工作项
        $el.on('click', '.viewLinkClassName a', viewLink);//链接到
        $el.on('click', '.btnBack', back);
        $el.on('click', '.editSubTaskNextStatus a', bindEditTaskNextStatus);//开发状态
        $el.on('click', '#viewSubTaskEdit',editSubTasks);//修改
        $el.on('click', '#allotTasks',createSubTaskAssDialog);//分配
        $el.on('click', '.allotBtn',createSubTaskAssDialog);//子工作项分配
        $el.on('click', '.sliderContainer .tri', bindTableSwitch)//折叠
        //$el.on('click', '.t-tabs-items li', bindTableSwitch);
        $el.on('click', '.viewSubTaskEditBtn',editSubTasks);//修改
        $el.on('click', '.task-tab li', activeRecordInitTab);//tab切换
       // $('#tabList li.' + tplId).on('click', tabActive);
    };

    var back = function() {
        tab.switchTab(viewSubTaskData.menuId);
        tab.destroy("viewSubTaskTab");
        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
    }
    //折叠
   
    var bindTableSwitch = function(e){
        $(this).toggleClass('tri-left');
        $(this).parent('.t-list-title').siblings().stop().slideToggle();
    }


    //下载
    /*var downloadFile=function(item){
        Util.ajax.getJson(AjaxPath.project+"/uploadFile/download/"+item.data.id, {}, function(result, isok) {

        })
    };*/


   
    //新建子工作项
    var addTask = function(){
        tab.createTab({
            title: '新建子工作项',
            closeable: 1, //是否可以关闭 0false不可以|1true可以
            className: 'addSubTaskTab'
        });
        tab.switchTab('新建子工作项');
        require(['js/requirement/addSubTask'], function(addSubTaskContent) {
            var result = new addSubTaskContent({}, viewSubTaskData, tab);
            tab.content(result.content);
        });

        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
    };
   
    //table
    var tables = function(e){

        Util.ajax.getJson(AjaxPath.demand+"/requires/" + viewSubTaskData.id + '?type=2', {}, function(result, isok) {
            var item=result.beans,
                requireTitles="";
                $(item.position).each(function(index,res){
                    requireTitles+= '/'+res.requireTitle;

                });
            item.viewSubTaskExcuter = "viewSubTaskExcuter";
            item.linkClassName = "viewLinkClassName";
            item.viewSubTaskStatus = "viewSubTaskStatus";
            item.requireTitles = requireTitles;
            
            $(".viewSubTaskTop", $el).html(Util.hdb.compile(tabletpl)(item));
            
        });
    }

    var viewLink = function(){
        //tab.destroy("viewSubTaskTab");
        $(".ui-popup-backdrop, .ui-popup-focus").remove();
        var dataType = $(this).attr("dataType");
        var dataId = $(this).attr("dataId");

        var viewSubTaskData = {};
        viewSubTaskData.menuId = tplId;
        viewSubTaskData.id = dataId;
        viewSubTaskData.type = dataType;
        console.log(viewSubTaskData)

        tab.createTab({
            title: ((viewSubTaskData.type==1 || viewSubTaskData.type==="3") ? '查看工作项' : viewSubTaskData.type==2 ? '查看子工作项' : ''),
            closeable: 1, //是否可以关闭 0false不可以|1true可以
            className: ((viewSubTaskData.type==1 || viewSubTaskData.type==="3") ? 'viewRequirement' : viewSubTaskData.type==2 ? 'viewSubTaskTab' : '')
        });
        tab.switchTab((viewSubTaskData.type==1 || viewSubTaskData.type==="3") ? '查看工作项' : viewSubTaskData.type==2 ? '查看子工作项' : '');

        if((viewSubTaskData.type==1 || viewSubTaskData.type==="3")){
            require(['js/requirement/viewRequirement'], function(viewSubTaskContent) {
                var result = new viewSubTaskContent({}, viewSubTaskData, tab);
                tab.content(result.content);
            });
        }else if(viewSubTaskData.type==2){
            require(['js/requirement/viewSubTask'], function(viewSubTaskContent) {
                var result = new viewSubTaskContent({}, viewSubTaskData, tab);
                tab.content(result.content);
            });
        }
                
    }

    //附件
    var fileTable = function (){
        var config = {
            el: $('#viewSubTaskAnnexTable', $el),
            ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置；慎用
                method:'GET'
            },
            field: {
                /* boxType: 'checkbox',*/
                key: 'id',
                items: [
                    {
                        text: '附件名称',
                        title: 'fileName',
                        name: 'fileName',
                        className: 'w90',
                        width:200,
                        click: function (e, val, item) {
                            //downloadFile(item);

                        },
                        render: function (item, val) {
                            //console.log(item);
                            return  '<a href="'+AjaxPath.project+'/uploadFile/download?id='+item.id+'">'+val+'</a>';
                        }
                    },
                    {
                        text: '附件大小',
                        title: 'fileSize',
                        name: 'fileSize',
                        className: 'w90',
                        width:150,
                        render: function (item, val) {
                            var fileSize = (val/1024>1024) ? ((val/1024/1024>1024) ? (val/1024/1024/1024).toFixed(2)+' GB' : (val/1024/1024).toFixed(2)+' MB') : (val/1024).toFixed(2)+' KB';
                            return '<div >' + fileSize + '<div/>';
                        }
                    },
                    {
                        text: '上传时间',
                        title: 'createTime',
                        name: 'createTime',
                        className: 'w90',
                        width:130,
                        render: function (item, val) {
                            return new Date(val).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    }]
            },
            page: {
                customPages: [2, 3, 5, 10, 15, 20, 30, 50], //可选择每页显示多少条
                perPage: 5, //默认每页显示多少条记录
                total: true
            },
            data: {
                url: AjaxPath.project + '/attachment?businessId='+ viewSubTaskData.id +'&businessType=require'

            }
        };
        list = new List(config);
        list.search();
    };
   /* var fileUp = function () {
        var uploadConfig = {
            el: $("#viewSubTaskAnnexTable", $el), //组件绑定的容器
            className: 'upload', //组件外围的className
            url:  AjaxPath.project + '/uploadFile/upload', //组件上传的后台接口
            // deleteUrl: 'data/upload.json?name=[name]', //组件上传的后台接口
            paramName:'textFile',
        };
        var filesUpload = new Upload(uploadConfig);

        filesUpload.on('download',function(e,data){
            console.log(data)
            if(data.attId){
                delFlag=true;
                data=data.attId;
                uploadDown(e,data);
            };
            // uploadDelete(e,data)
            //e新增自定义remove方法，可根据服务端文件处理结果删除文件列表中的当前行
        })
    };

    function uploadDown(e,data){
        //e新增自定义remove方法，可根据服务端文件处理结果删除文件列表中的当前行
        if(delFlag){
            window.location.href=AjaxPath.project+'/uploadFile/download?id='+data.attId;
        }
    }

    var fileTable = function(){
        Util.ajax.getJson(AjaxPath.project + '/attachment?businessId='+ viewSubTaskData.id +'&businessType=require', {}, function(result, isok){
            if(result.returnCode==="0000"){
             //console.log(result.beans);
                $('#viewSubTaskAnnexTable .files', $el).prepend(fileList(result.beans));
                $('#viewSubTaskAnnexTable .fileInput', $el).remove();
                $('#viewSubTaskAnnexTable table tr').each(function(index, item){
                    $('#viewSubTaskAnnexTable table tr').eq(index).find("th:last").remove();
                    $('#viewSubTaskAnnexTable table tr').eq(index).find("td:last").remove();
                })
            }
            
        });
    };*/

    //子工作项
    var taskInit = function (e){
        viewSubTaskTable = new List({
            el: $('.subtasks', $el),
            ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置；慎用
                method:'GET'
            },
            field: {
                boxType: 'radio',
                key: 'id',
                items: [
                    {
                        text: '子工作项名称',
                        title: 'requireTitle',
                        name: 'requireTitle',
                        className: 'w90',
                        width:150,
                        click: function (e, val, item) {

                            checkTask(e, item);

                        },
                        render: function (item, val) {
                            return '<a href="javascript:;" class="text-overflow" style="line-height:36px;display:block;outline:none">' + val + '</a>';
                        }
                    },
                    {
                        text: '状态',
                        title: 'statusName',
                        name: 'statusName',
                        className: 'w90',
                        width:130
                       
                    },
                    {
                        text: '优先级',
                        title: 'priStatusName',
                        name: 'priStatusName',
                        className: 'w90',
                        width:130
                    },
                    {
                        text: '经办人',
                        title: 'tryPeopleName',
                        name: 'tryPeopleName',
                        className: 'w90',
                        width:150
                    },
                    {
                        text: '创建时间',
                        title: 'createTime',
                        name: 'createTime',
                        className: 'w90',
                        width:150,
                       /* click: function (e, val,item) {
                            creatDialog(e, item);
                            // setTimeout(function(){ $('#isTrue').on('click',save); },100);
                            // $('#isTrue').on('click',save);
                        },*/
                        render: function (item, val) {
                            return new Date(val).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        text: '更新时间',
                        title: 'updateTime',
                        name: 'updateTime',
                        className: 'w90',
                        width:150,
                        render: function (item, val) {
                            return new Date(val).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        text: '操作',
                        title: '',
                        name: '',
                        width:130,
                        className: 'w90',
                        click: function (e, val, item) {
                            // console.log(val,item);
                        },
                        render: function (item, val) {
                            return '<div class="fn-center"><button class="t-btn t-btn-blue t-btn-xs  allotBtn" style="margin-right:8px;"><a style="color:#fff">分配</a></button><button class="t-btn t-btn-blue t-btn-xs viewSubTaskEditBtn" ><a style="color:#fff">修改</a></button></div>';
                        }
                    }]
            },
            page: {
                customPages: [2, 3, 5, 6, 10, 15, 20, 30, 50], //可选择每页显示多少条
                perPage: 5, //默认每页显示多少条记录
                total: true
            },
            data: {
                url: AjaxPath.demand + '/requires/tasks/'  + viewSubTaskData.id
            }
        });
        viewSubTaskTable.search();
    };
   


    //查看子工作项
    var checkTask= function(e, data){
        tab.destroy("viewSubTaskTab");

        var viewSubTaskTable = data.data;
        viewSubTaskTable.menuId = tplId;

        tab.createTab({
            title: (viewSubTaskTable.type===1 ? '查看工作项' : viewSubTaskTable.type===2 ? '查看子工作项' : ''),
            closeable: 1, //是否可以关闭 0false不可以|1true可以
            className: (viewSubTaskTable.type===1 ? 'viewRequirementTab' : viewSubTaskTable.type===2 ? 'viewSubTaskTab' : '')
        });
        tab.switchTab(viewSubTaskTable.type===1 ? '查看工作项' : viewSubTaskTable.type===2 ? '查看子工作项' : '');

        if(viewSubTaskTable.type===1){
            require(['js/requirement/viewRequirement'], function(viewSubTaskContent) {
                var result = new viewSubTaskContent({}, viewSubTaskTable, tab);
                tab.content(result.content);
            });
        }else if(viewSubTaskTable.type===2){
            require(['js/requirement/viewSubTask'], function(viewSubTaskContent) {
                var result = new viewSubTaskContent({}, viewSubTaskTable, tab);
                tab.content(result.content);
            });
        }

        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
    }

   
    //修改子工作项
    var editSubTasks = function(e, index){
        tab.destroy("viewSubTaskTab");
        tab.createTab({
            title: '修改子工作项',
            closeable: 1, //是否可以关闭 0false不可以|1true可以
            className: 'editSubTaskTab'
        });
        tab.switchTab('修改子工作项');

        var data = '';
        if(e.target.id=='viewSubTaskEdit'){
            data = viewSubTaskData;
        }else{
            data = viewSubTaskTable.getSelected();
        }

        data.menuId = tplId;
        require(['js/requirement/editSubTask'], function(editSubTaskContent) {
            var result = new editSubTaskContent({}, data, tab);
            tab.content(result.content);
        });

        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
    }
    //活动日志
    var switchTab = function(index) {
        $(".t-tabs-items li", $el).eq(index).trigger('click');
    }

    var bindTableSwitch = function(e){
        $(this).toggleClass('tri-left');
        $(this).parent('.t-list-title').siblings().stop().slideToggle();
    };
    var search = function(pageIndex) {
        var data = {};
        data.useMode = $(".task-tab li.actived").attr("data");
        list.search(data,pageIndex ? pageIndex : "");
    };
    
    var activeRecordInit = function(){
        var config = {
            el: $('.activeRecordContainer', $el),
            ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置；慎用
                method:'GET'
            },
            field: {
               /* boxType: 'checkbox',*/
                key: 'id',
                items: [
                    {
                        text: '经办人',
                        name: 'createrName',
                        className: 'w90',
                        width:100
                    },
                    {
                        text: '记录',
                        name: '',
                        className: 'w50 text-break',
                        width:400,
                        render: function (item, val) {
                            return '<div class="fn-left">'+ "于&nbsp;&nbsp;"+ new Date(item.createTime).Format("yyyy-MM-dd hh:mm:ss")+'&nbsp;&nbsp;'+item.typeName+ '了&nbsp;&nbsp;' +item.businessType+"：<a href='javascript:;' >"+item.businessTitle+"</a>"+item.content+'</div>';
                        }
                       

                    }]
            },
            page: {
                customPages: [2, 3, 5, 6, 10, 15, 20, 30, 50], //可选择每页显示多少条
                perPage: 5, //默认每页显示多少条记录
                total: true
            },
            data: {
                url:AjaxPath.project + '/logInfo/query?businessId='+ viewSubTaskData.id +'&businessType=task'
                // url:"http://192.168.91.172:8089/devops-project/projects"
                //url:"../../../data/list1.json"
            }
        };
        
        list = new List(config);
        list.search();
        $("#oTabel" ,$el).find(".sn-list-header").hide();
    };

    var activeRecordInitTab = function(e){                                                                                                              
        var data={};
        $(this).addClass('actived').siblings().removeClass('actived');
        data.type = $(this).attr("data");
        list.search(data);
    };
   

    //状态
    var getEditTaskNextStatus = function(statusId){
        Util.ajax.getJson(AjaxPath.demand+"/requires/" + viewSubTaskData.id + '?type=2', {}, function(result, isok) {
            var item=result.beans,
                requireTitles="";
                $(item.position).each(function(index,res){
                    requireTitles+= '/'+res.requireTitle;

                });
            item.viewSubTaskExcuter = "viewSubTaskExcuter";
            item.linkClassName = "viewLinkClassName";
            item.viewSubTaskStatus = "viewSubTaskStatus";
            item.requireTitles = requireTitles;
            
            $(".viewSubTaskTop", $el).html(Util.hdb.compile(tabletpl)(item));
            Util.ajax.getJson(AjaxPath.project + '/workFlows/getFLowActions?modual=require&type=requireStatus&flowFrom=' + statusId +"&systemId="+ viewSubTaskData.systemId, {}, function(result, isok){
                if(result.returnCode==='0000'){
                    var str = "";
                    $(result.beans).each(function(index, item){
                        str += '<a href="javascript:;" class="t-btn t-btn-white" data="'+ item.toValue +'">'+ item.description +'</a>';
                    })
                    // $(".editSubTaskNextStatus", $el).html(str);
                    $(".editSubTaskNextStatus").html(str);
                }
            })
            
        });
        /*Util.ajax.getJson(AjaxPath.project + '/workFlows/getFLowActions?modual=require&type=requireStatus&flowFrom=' + statusId +"&systemId="+ viewSubTaskData.systemId, {}, function(result, isok){
            if(result.returnCode==='0000'){
                var str = "";
                $(result.beans).each(function(index, item){
                    str += '<a href="javascript:;" class="t-btn t-btn-white" data="'+ item.toValue +'">'+ item.description +'</a>';
                })

                // $(".editSubTaskNextStatus", $el).html(str);
                $(".editSubTaskNextStatus").html(str);
            }
        })*/
    }

    var bindEditTaskNextStatus = function(){
        var config = null;
        var data = {};
            data.id = viewSubTaskData.id;
            data.updater = $cookie.get("userId");
            // data.updater = 1;
            data.status = $(this).attr("data");
            data.type = 2;
        Util.ajax.postJson(AjaxPath.demand + '/requires/status', JSON.stringify(data), function(result, isok){
            if (result.returnCode==="0000") {
                config = {
                    mode: 'confirm', // 对话框模式，默认normal标准|confirm浮动层|confirm确认对话框
                    title:'提示',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false, //是否显示取消按钮（强制执行，可在confirm模式下生效），可选项。 默认true(显示)
                    modal:true,
                    content: '<div style="text-align:center;margin-top:50px">修改状态成功</div>' ,// 对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                };
                dialog = new Dialog(config);
                dialog.on('onclose',function(){
                    getEditTaskNextStatus(result.beans.status);
                    console.log(result.beans.status);
                    $(".viewSubTaskStatus").text(result.beans.statusName);
                    //editSubTaskStatusSelect.setValue('"' + result.beans.status + '"');
                });
                
            }else{
                config = {
                    mode: 'confirm', // 对话框模式，默认normal标准|confirm浮动层|confirm确认对话框
                    title:'提示',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false, //是否显示取消按钮（强制执行，可在confirm模式下生效），可选项。 默认true(显示)
                    modal:true,
                    content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>' ,// 对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                };
                dialog = new Dialog(config);
            }
        },'application/json')
    }

    //分配
    var subTaskAssSelect = function(id){
        Util.ajax.getJson(AjaxPath.project +'/dropdown?modual=project&type=userId&systemId='+ viewSubTaskData.systemId, {}, function(result, isok){
            tryPeopleData = result.beans;
            viewSubTaskAssSelect = new Select({
                el:$("#viewSubTaskAss"),       //要绑定的容器
                ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置，<span class="s">慎用</span>
                    method:'GET'
                }, 
                label:'<i style="color:red;padding:2px;"></i>分配给:', //下拉框单元左侧label文本，可不配置
                selectText:false,       //是否显示  ‘选择|清除’  模式
                name:'tryPeople',    //下拉框单元右侧下拉框名称
                disabled:false,     //组件是否被禁用
                topOption:"", //设置最顶部option的text属性
                value:0,//初始选中项设置 默认是按value，如果你想按id设置 也可以 value:[&quot;id&quot;,1],这样设置
                textField:"value",   //设置下拉框内容，填写数据中对应的字段名
                valueField:"key",//设置下拉框value，填写数据中对应的字段名
                datas: tryPeopleData,         //数据源
                loadAtClick:false,// true--第一次点击时渲染|false或不配置--初始化时渲染
                dataReady:function(){
                    console.log("获取经办人");
                } //select的DOM结构加载完后执行
                //  url:'../data/select.json'  //数据源，不建议使用，后期将会移除
            });
            viewSubTaskAssSelect.setValue('"' + id + '"'); //editSubTaskData.tryPeople
        });
    }

    var createSubTaskAssDialog = function(e){
        var subTaskData = {};
        var who = null;
        if(e.target.id.indexOf("allotTasks")>-1){
            subTaskData = viewSubTaskData;
            who = true;
        }else{
            subTaskData = viewSubTaskTable.getSelected();
            console.log(subTaskData);
            viewSubTaskAssSelectId = subTaskData.tryPeople;
            who = false;
        }

        var data = {};
            data.formClassName = "detailEditSubTaskAssForm";
            data.selectName = "viewSubTaskAss";
        var config = {
            mode: 'confirm', //对话框模式，默认normal标准|tips浮动层|confirm确认对话框
            title: '任务分配', //对话框标题，
            content: Util.hdb.compile(taskAss)(data), //对话框内容，可以是字符串、html代码段,tpl对象。默认为loading状态（由点组成的圈。大段代码建议使用 tpl。
            ok: function() { 
                console.log('点击了确定按钮');
                createSubTaskAss(subTaskData, who);
                return true;
            }, 
            cancel: function() {
                return true;
            },
            cancelValue: '取消', //取消按钮的文本 默认是 ‘关闭’
            okValue: '确定', //取消按钮的文本 默认是 ‘关闭’
            cancelDisplay: true, //是否显示取消按钮 默认true显示|false不显示
            width: 600, //对话框宽度，normal默认值为600，confirm默认值为300，tips默认值为240
            height: 300, //对话框高度，normal默认值为400，confirm默认值为180，tips默认值为80
            maxWidth: 240,//设置tips对话框的最大宽度,默认为240px。仅在tips对话框下生效，该项存在时，width属性将失效。
            maxHeight: 'auto', //设置tips对话框的最大高度,默认为auto。仅在tips对话框下生效，该项存在时，height属性将失效。
            padding:'0 16px 1em 10px',//(默认值: 继承 css 文件设置) 设置消息内容与消息容器的填充边距，即 style padding属性
            align: 'bottom left',//设置对话框与其他元素的对齐方式。仅在show(elem)与showModal(elem)传入元素时生效。默认值: "bottom left"。可选："top left" "top" "top right" "right top" "right" "right bottom" "bottom right" "bottom" "bottom left" "left bottom" "left" "left top"。
            skin: 'dialogSkin dialogSkin2',//设置对话框额外的className参数,多个className请使用空格隔开。
            fixed: false, //是否开启固定定位 默认false不开启|true开启
            quickClose: false, //点击空白处快速关闭 默认false不关闭|true关闭
            modal: true ,//是否开启模态框状态  默认false不开启|true开启,confirm默认状态为true
            backdropBackground:'#000',//设置遮罩颜色，默认 #000。
            backdropOpacity:0.7, //设置遮罩透明度，默认 0.7，取值范围：0~1 。
            beforeOpen: function() {
                console.log('对话框打开时执行。');
                subTaskAssSelect(viewSubTaskAssSelectId);                   
            }, //对话框打开之前执行。
            escClose:true,//esc键快速关闭对话框，默认为true
            zIndex:990   // 对话框的z-index值，默认是1024。
        };
        dialog = new Dialog(config);
    }

    var createSubTaskAss = function(datas, who){
        var config = null;
        var data = Form.serialize($('.detailEditSubTaskAssForm'));
            data.updater = $cookie.get("userId");
             //data.updater = 1;
            data.type = 2;

        Util.ajax.postJson(AjaxPath.demand + '/requires/allot/'+ datas.id, data, function(result, isok) {
            if(result.returnCode==="0000") {
                config = {
                    mode: 'confirm', // 对话框模式，默认normal标准|confirm浮动层|confirm确认对话框
                    title:'提示',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false, //是否显示取消按钮（强制执行，可在confirm模式下生效），可选项。 默认true(显示)
                    modal:true,
                    content: '<div style="text-align:center;margin-top:50px">分配成功</div>' ,// 对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                };
                dialog = new Dialog(config);
                if(who){
                    viewSubTaskAssSelectId = result.beans.userId;
                    $(".viewSubTaskExcuter").text(result.beans.userName);
                }else{
                    viewSubTaskTable.search({},viewSubTaskTable.pageIndex);
                }
                // dialog.on('onclose',function(){
                //     back();
                // });
            } else {
                config = {
                    mode: 'confirm', // 对话框模式，默认normal标准|confirm浮动层|confirm确认对话框
                    title:'提示',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false, //是否显示取消按钮（强制执行，可在confirm模式下生效），可选项。 默认true(显示)
                    modal:true,
                    content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>' ,// 对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                };
                dialog = new Dialog(config);
            }
        });
    }

    var getEditTaskData = function(){
        Util.ajax.getJson(AjaxPath.demand + '/requires/'+ viewSubTaskData.id +'?type=2'+ ( getQueryString("from") ? '&from=' + getQueryString("from") : ''), {}, function(result, isok){
            if(result.returnCode==="0000"){
                viewSubTaskData = result.beans;
                //console.log(viewSubTaskData);
                viewSubTaskAssSelectId = viewSubTaskData.tryPeople;

                // var positionStr = "";
                // $(viewSubTaskData.position).each(function(index, item){
                //     positionStr += item.requireTitle + '/';
                // })
                // positionStr = positionStr.substring(0,positionStr.length-1);
                // $(".editSubTaskPosition", $el).html(positionStr);

                // getEditTaskNextStatus(editSubTaskData.status);
                // inSelect();
                // initDate();
                // fileUp();
                // fileTable();//修改时用
                // initList();
                // editSubTaskValidation();
                // formInit();
                // tables();
                getEditTaskNextStatus(viewSubTaskData.status);
                fileTable();
                taskInit();
                activeRecordInit();
                eventInit();
            }else {
                config = {
                    mode: 'confirm', // 对话框模式，默认normal标准|confirm浮动层|confirm确认对话框
                    title:'提示',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false, //是否显示取消按钮（强制执行，可在confirm模式下生效），可选项。 默认true(显示)
                    modal:true,
                    content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>' ,// 对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                };
                dialog = new Dialog(config);
            }
        });
    }

    return initialize;
});